<template>
    <h3 style="text-align: center;">
    用户详细信息添加
    </h3>
    <table class="table-bordered" border="1">
        <tr>
            <td>
                用户名
            </td>
            <td>
                <input type="text" v-model="Info.T_Iname" placeholder="请输入用户名" />
            </td>
        </tr>
        <tr>
            <td>
                联系方式
            </td>
            <td>
                <input type="text" v-model="Info.T_Iphone" placeholder="请输入联系方式" />
            </td>
        </tr>
        <tr>
            <td>
                年龄
            </td>
            <td>
                <input type="text" v-model="Info.T_Iage" placeholder="请输入年龄" />
            </td>
        </tr>
        <tr>
            <td>
                身份
            </td>
            <td>
                <select v-model="Info.T_Uid">
                    <option value="0">全部</option>
                    <option v-for="item in Binds" :value=item.T_Uid>{{item.T_Uname}}</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>
                身份证号
            </td>
            <td>
                <input type="text" v-model="Info.T_Iicard" placeholder="请输入身份证号" />
            </td>
        </tr>
        <tr>
            <td>
                出生日期
            </td>
            <td>
                <input type="date"  v-model="Info.T_IDate" />
                
            </td>
        </tr>
        <tr style="text-align: center;">
            <td colspan="2">
                <button @click="AddInve">添加</button>
            </td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import { ref } from 'vue';
///显示信息双项绑定
const Info = ref({
    T_Id:0,
    T_Iname:'',
    T_Iphone:'',
    T_Iage:0,
    T_Iicard:'',
    T_IDate:'',
    T_Uid:'',
})
const Binds=ref([{
    T_Uid:0,
    T_Uname:'',
}])
import {useMainStore}from '../../store/index.ts'
const store=useMainStore()
const T_Id=store.T_Id;
import { onMounted } from 'vue';
import { useRouter } from 'vue-router';
const router = useRouter();
onMounted(() => {
    Bindss();
})
import axios from 'axios';
//绑定下拉
const Bindss=()=>{
    axios.get("https://localhost:44356/api/Userinfo/Binder")
    .then((res)=>{
        Binds.value=res.data;
    })
    .catch
    ((err)=>{
        console.log(err);
    })
}
///添加
const AddInve=()=>{
    axios.post("https://localhost:44356/api/Userinfo/AddInverInfo",
    {
        T_Id:T_Id,
        T_Iname:Info.value.T_Iname,
        T_Iphone:Info.value.T_Iphone,
        T_Iage:Info.value.T_Iage,
        T_Iicard:Info.value.T_Iicard,
        T_IDate:Info.value.T_IDate,
        T_Uid:Info.value.T_Uid,
    })
    .then((res)=>{
        if(res.data>0)
        {
            alert("添加成功");
            router.push('/UserLogin');
        }
        else{
            alert("添加失败");
        }
        console.log(res.data);
    })
    .catch
    ((err)=>{
        console.log(err);
    })
}

</script>